ga.core.algorithm.automatic
Class SGAGeneration<T extends IIndividual<T>>

java.lang.Object
  extended by ga.core.algorithm.automatic.SGAGeneration<T>
Type Parameters:
T - The generic type of individuals.
All Implemented Interfaces:
GA<T>

public class SGAGeneration<T extends IIndividual<T>>
extends java.lang.Object
implements GA<T>

Generational simple genetic algorithm.

Since:
11.08.2012
Author:
Stephan Dreyer

Field Summary
private static int CRITICAL_WHILE_ITERATIONS
           
private  ICrossoverOp<T> crossoverOp
           
private  GAContext gaContext
           
private  int generation
           
private static java.util.logging.Logger LOGGER
           
private  IMutationOp<T> mutateOp
           
private  IPopulation<T> population
           
private  ISelector<T> selector
           
private  boolean useEliteStrategy
           
private  boolean validate
           
private  IValidator<T> validator
           
 
Fields inherited from interface ga.core.GA
KEY_EVALUATED_INDIVIDUALS_MIN_COUNT, KEY_GENOME_MAX_LENGTH, KEY_GENOME_MIN_LENGTH, KEY_INIT_INDIVIDUAL, KEY_INIT_INDIVIDUAL_PERCENTAGE, KEY_INTERVAL_FITNESS_MAX_WIDTH, KEY_VALIDATION_SPACE
 
Constructor Summary
SGAGeneration(IPopulation<T> population, IFitnessEvaluator<T> evaluator, ISelector<T> selector, IMutationOp<T> mutateOperator, ICrossoverOp<T> crossoverOperator, boolean useEliteStrategy)
          Creates a new generational SGA.
SGAGeneration(IPopulation<T> population, IFitnessEvaluator<T> evaluator, ISelector<T> selector, IMutationOp<T> mutateOperator, ICrossoverOp<T> crossoverOperator, boolean useEliteStrategy, GAContext context)
          Creates a new generational SGA.
 
Method Summary
private  IndividualList<T> doReproduction()
          Selects two individuals, recombines and mutates them.
 IPopulation<T> getPopulation()
          Getter for the population.
 void init()
          Initializes the algorithm and population.
 void setValidate(boolean validate)
          Setter to enable/disable individual validation.
 void setValidator(IValidator<T> validator)
          Set the individual validator for the algorithm.
 void step()
          Do one step.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER

CRITICAL_WHILE_ITERATIONS

private static final int CRITICAL_WHILE_ITERATIONS
See Also:
Constant Field Values

population

private final IPopulation<T extends IIndividual<T>> population

selector

private final ISelector<T extends IIndividual<T>> selector

mutateOp

private final IMutationOp<T extends IIndividual<T>> mutateOp

crossoverOp

private final ICrossoverOp<T extends IIndividual<T>> crossoverOp

validator

private IValidator<T extends IIndividual<T>> validator

gaContext

private final GAContext gaContext

validate

private boolean validate

useEliteStrategy

private boolean useEliteStrategy

generation

private int generation
Constructor Detail

SGAGeneration

public SGAGeneration(IPopulation<T> population,
                     IFitnessEvaluator<T> evaluator,
                     ISelector<T> selector,
                     IMutationOp<T> mutateOperator,
                     ICrossoverOp<T> crossoverOperator,
                     boolean useEliteStrategy,
                     GAContext context)
Creates a new generational SGA.

Parameters:
population - Population for the GA.
evaluator - The automatic evaluator.
selector - The selector.
mutateOperator - The mutation operator.
crossoverOperator - The crossover operator.
useEliteStrategy - Use elite strategy or not.
context - The ga context.
Since:
11.08.2012

SGAGeneration

public SGAGeneration(IPopulation<T> population,
                     IFitnessEvaluator<T> evaluator,
                     ISelector<T> selector,
                     IMutationOp<T> mutateOperator,
                     ICrossoverOp<T> crossoverOperator,
                     boolean useEliteStrategy)
Creates a new generational SGA. The required ga context is newly created.

Parameters:
population - Population for the GA.
evaluator - The automatic evaluator.
selector - The selector.
mutateOperator - The mutation operator.
crossoverOperator - The crossover operator.
useEliteStrategy - Use elite strategy or not.
Since:
11.08.2012
Method Detail

init

public void init()
Description copied from interface: GA
Initializes the algorithm and population.

Specified by:
init in interface GA<T extends IIndividual<T>>

step

public void step()
Description copied from interface: GA
Do one step. This could create a new generation (generation-based GA) or do one reproduction (steady state).

Specified by:
step in interface GA<T extends IIndividual<T>>

doReproduction

private IndividualList<T> doReproduction()
Selects two individuals, recombines and mutates them.

Returns:
A list of two offsprings.
Since:
11.08.2012

setValidate

public void setValidate(boolean validate)
Description copied from interface: GA
Setter to enable/disable individual validation. To validate, this must be set to true and a validator must be set.

Specified by:
setValidate in interface GA<T extends IIndividual<T>>
Parameters:
validate - Enable/disable validation.

setValidator

public void setValidator(IValidator<T> validator)
Description copied from interface: GA
Set the individual validator for the algorithm. To validate, this must be not be null and validate must have been activated.

Specified by:
setValidator in interface GA<T extends IIndividual<T>>
Parameters:
validator - The individual validator.

getPopulation

public IPopulation<T> getPopulation()
Description copied from interface: GA
Getter for the population.

Specified by:
getPopulation in interface GA<T extends IIndividual<T>>
Returns:
The population.